
var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var openHelper = require("helper/open");
var bizzType = require("helper/bizzType");
var userUtil = require("helper/user");
var http = require("helper/httpSilence");
var pubUrl = require("url/pub");
var orderHelper = require("helper/order");
var communityUtil = require("helper/community");

var activityUrl = require("url/activity");
var signHttp = activityUrl.url.sign.create;

var rootview = ui("$");
var btnALayout = ui("btnALayout");
var labelSign=ui("labelSign");
var aLayoutSign=ui("aLayoutSign");

var isConcern = 2;//是否关注 1-是，2-否
var isPraised = 2;//是否关注 1-是，2-否
var bizzId;
var bizzType;
var beCommentedId = null; //被回复的评论ID
var beCommentedName = null;//被回复的用户名
var praiseImg = ui("praiseImg");
var iconPraise = ["source://image/common/praise.png","source://image/common/praise1.png"];
//输入框--得到焦点
/*textContent.on("focusIn", function(data, e) {
	do_Page.fire("focusIn");
})*/
var status,idleId,quantity,type,userId;
//初始化
do_Page.on("initIdle",function(data) {
	idleId=data.idleId;
	bizzId=idleId;
	bizzType=data.bizzType;
	status=data.status;
	type=data.type;
	quantity=data.quantity;
	isPraised = data.isPraised;
	userId=data.userId;
	if(status==3){
		aLayoutSign.bgColor="C0C0C0FF";
		labelSign.text = "已解决";
	}else{
		if(type==3){
			if(quantity==1){
				labelSign.text="我想要";
				aLayoutSign.bgColor="FE7E0AFF";
			}else{
				labelSign.text="已被预定";
				aLayoutSign.bgColor="FE7E0AFF";
			}
		}else{
			labelSign.text=data.typeName;
			aLayoutSign.bgColor="C0C0C0FF";
		}
	}
	if(data.isPraised==1){
		//点亮点赞按钮
		praiseImg.source = iconPraise[1];
	}
});
//报名
aLayoutSign.on("touch", "", 5000, function(data) {
	if (status!=3&&quantity==1&&type==3) {
		if (null == userUtil.loginToken() || '' == userUtil.loginToken()) {
			nf.toast("请先登录。")
			return;
		}
		if (userId == userUtil.userId()) {
			nf.toast("请不要购买自己的产品。")
			return;
		}
		nf.confirm("您确定要购买吗？", "报名", "确定", "取消", function(data, e) {
			if(data == 1){
				openHelper.open("source://view/idle/detail/toOrder.ui", {
					id : idleId
				});
			}
		})
	}
});
//点赞
var footPraise = ui("footPraise");
footPraise.on("touch", "", 300,  function(data, e) {
	var addParams = {
        bizzId:bizzId,
        bizzType:bizzType,
        communityId:communityUtil.communityVisitId()
	};
	if(isPraised == 1){
		//如果已关注，再次点击则取消关注
		http.post(pubUrl.url.praise.doCancle,addParams,function(data){
			praiseImg.source = iconPraise[0];
			isPraised = 2;
			do_Page.fire("onPraiseBack", data.praiseUserList);
		});
	}else{
		http.post(pubUrl.url.praise.doAdd,addParams,function(data){
			praiseImg.source = iconPraise[1];
			isPraised = 1;
			do_Page.fire("onPraiseBack", data.praiseUserList);
		});
	}	
});
/*评论*/
var footComment = ui("footComment");
footComment.on("touch", "", 300, function() {
	var datas = {"bizzId":bizzId,"bizzType":bizzType,"beCommentedId":null};
	do_Page.fire("bottomShow",datas);
});



